package cn.jx.asc.socket;

import java.io.IOException;
import java.net.*;
import java.util.*;

import org.json.JSONObject;

/*
 * 用于监听端口
 * 监听来自终端的连接
 */
public class MainForListen extends Thread{
    int port = 8018; // 监听的端口

    ServerSocket server = null;
    Socket socket = null;

    public MainForListen() {

    }

    public void run() {
        try {
            server = new ServerSocket(port); // 开启服务器监听
            System.out.println("***Server start success***");
            while(true){
                socket = server.accept(); // 等待用户的连接
                System.out.println("***socket have been start,waiting for connect***");
                new CommunicationWithTerminal(socket).start(); // 监听到终端的连接，开启新的socket与之通信
            }
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("***ServerSocket start fail***");
        }
    }

}
